﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace BaoVeBienCuong.Store
{
    public class TuongButton
    {
        private int Type;//0-3 là button chọn tướng, 4-6 là button cấp, 7 là button mở khóa
        private Vector2 position;
        private Vector2 size;
        private Texture2D image;
        private bool isSelect;
        private float scale = 2.0f / 3.0f;
        public TuongButton(int type)
        {
            Type = type;
            if (Type < 4)
            {
                scale = 0.7f;
                size = new Vector2(32, 32) * scale;
                position = new Vector2(Type * (size.X + 5) + 150, 450);
            }
            else if (Type < 7)
            {
                scale = 0.6f;
                size = new Vector2(113, 61) * scale;
                position = new Vector2((Type - 4) * (size.X + 15) + 550, 350);
            }
            else
            {
                scale = 0.6f;
                size = new Vector2(251, 70) * scale;
                position = new Vector2(600, 420);
            }
            if (Type == 0 || Type == 4) isSelect = true;
            else isSelect = false;
        }
        public void Load(ContentManager content)
        {
            if (Type < 4)
            {
                image = content.Load<Texture2D>("images/store/swipeButton");
            }
            else if (Type < 7)
            {
                image = content.Load<Texture2D>("images/store/levelButton");
            }
            else
            {
                image = content.Load<Texture2D>("images/selectMap/mapScreenButton");
            }
        }
        public void Draw(SpriteBatch sprite)
        {
            if (Type < 4)
            {
                sprite.Draw(image, position, new Rectangle(32, 0, 32, 32), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(0, 0, 32, 32), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
            }
            else if (Type < 7)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(113 * (Type - 4), 0, 113, 61), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(113 * (Type - 4), 0, 113, 61), Color.White * 0.8f, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
            }
            else if (Type == 7)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(251, 140, 251, 70), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 140, 251, 70), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
            }
        }
        public bool isTouch(Vector2 posi)
        {
            isSelect = false;
            if (posi.X >= position.X && posi.X <= (position.X + size.X) && posi.Y >= position.Y && posi.Y <= (position.Y + size.Y))
            {
                MainPage.PlayHieuUng("Click", false);
                isSelect = true;
                return true;
            }
            else
            {
                return false;
            }
        }
        public void setTouch(bool x)
        {
            isSelect = x;
        }
        public int getType()
        {
            return Type;
        }
    }
}
